/*
 * auiMenu.h
 *
 *  Created on: 2012-7-19
 *      Author: Yangde
 */

#ifndef AUIMENU_H_
#define AUIMENU_H_

#include "wx/defs.h"
#include "wx/control.h"
#include "wx/sizer.h"
#include "wx/list.h"

#include "auipopupwindow.h"
#include "auimenubar.h"

enum auiMenuType{
	auiMENU_MAIN,
	auiMENU_SUB,
	auiMENU_POP
};

enum auiMenuItemStatus{
	auiItemNone         = 0,
	auiItemSelected     = 1<<0,
	auiItemChecked      = 1<<1,
	auiItemDisable      = 1<<2,
	auiItemShowSubmenu  = 1<<3
};

enum auiMenuItemType{
	auiItemNormal     = 0,
	auiItemHasIcon    = 1<<0,
	auiItemSubmenu    = 1<<1,
	auiItemCheck      = 1<<2,
	auiItemRadio      = 1<<3,
	auiItemSeparator  = 1<<4
};


class auiMenuItem{
public:
	auiMenuItem(auiMenu* parent,int itemid,const wxString& text,int type){
		this_menu = parent;
		item_type = type;
		item_id = itemid;
		item_text = text;
		item_status = auiItemNone;
		item_group = -1;

		item_bitmap = wxNullBitmap;
		item_has_bitmap = false;
	}

	int item_type;
	int item_id;
	int item_status;
	wxString item_text;
	int item_group;
	wxBitmap item_bitmap;
	bool item_has_bitmap;

	void SetSelect(bool select=true);
	bool IsSelect();

	void SetSubmenuOnShow(bool show=true);
	bool IsSubmenuOnShow();

	void SetChecked(bool check=true);
	bool IsChecked();

	void Disable();
	void Enable();
	bool IsDisable();


	void AttachSubMenu(auiMenu* sub){sub_menu=sub;}

	auiMenu* this_menu;
	auiMenu* sub_menu;
};

WX_DECLARE_OBJARRAY(auiMenuItem, auiMenuItemArray);

#define MENU_MOUSE_LEFT_DOWN  0
#define MENU_MOUSE_RIGHT_DOWN 1
#define MENU_MOUSE_MOVE       2


#define WM_LBUTTONDOWN 513
#define WM_RBUTTONDOWN 516


class auiMenu
{
public:
	auiMenu();

	~auiMenu();
	auiMenuItem* Append(int itemid,
	                       const wxString& text,
	                       int kind = auiItemNormal);
	auiMenuItem* Append(int itemid,
		                       const wxString& text,
		                       const wxBitmap &bitmap,
		                       int type = auiItemNormal);
	auiMenuItem* AppendSeparator();

	auiMenuItem* AppendSubMenu(auiMenu *submenu,
	                              const wxString& text);

	void SetMenuBar(auiMenuBar *b);
	void SetMenuParent(auiMenuBar *b, auiPopupWindow* p);

	void setTitle(const wxString &title);
	 const wxString& GetTitle() const { return menu_title; }

	void setSysKey(int  keycode){menu_key = keycode;}
	const int GetSysKey() const { return menu_key; }


	 void SetWidth(int w){menu_width = w;}
	 int GetWidth(){return menu_width;}

	 void SetMenuType(int t){menu_type = t;}
	 int GetMenuType(){return menu_type;}

	 int GetSelectItem();
	 void UnSelectItem();
	 void DismissSubMenu();
	 bool SelectItem(int index);

	 auiMenuItem* GetItem(int idnex);

	 int GetItemCnt()const {return menu_items.GetCount();}
	 int GetItemType(int index)const {return menu_items[index].item_type;}
     const wxString GetItemText(int index) const {return menu_items[index].item_text;}

	 bool IsMainMenu(){return (menu_type==auiMENU_MAIN);}
	 bool IsSubMenu() {return (menu_type==auiMENU_SUB);}
	 bool IsPopMenu() {return (menu_type==auiMENU_POP);}

	 void ResetParent();

	 bool MoveOnParent(wxPoint pos);
	 bool L_ClickOnParent(wxPoint pos);
	 bool R_ClickOnParent(wxPoint pos);
	 bool ProcessKeyDown(int keycode);
	 void Popup(wxWindow *focus,bool selectFirst=false);
	 void Dismiss();

	 auiMenuBar* menu_bar;
	 int menu_key;
	 auiMenu* m_parent;
	 auiPopupWindow* m_popupMenu;
	 int sys_char_i;


private:
	int             menu_type;
	wxString        menu_title;
	int             menu_width;
	auiMenuItemArray menu_items;
	int  max_group;



	int FindSysKeyChar(wxString &title);
};

#endif /* AUIMENU_H_ */
